package lex.dm.ui;

import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.JMenu;
import javax.swing.JMenuBar;

import lex.dm.DTree;
import lex.dm.ui.actions.*;
import lex.dm.utils.Actions;
import lex.dm.utils.DBMDUtils;

public class MainMenuBar extends JMenuBar {
	private JMenu metaData = null;

	public MainMenuBar() {
		ActionMap am = DTree.getApplication().getContext().getActionMap();
		// -----------------------------------
		JMenu load = new JMenu("Load");
		load.add(new WisconsinBreastCancerAction());
		load.add(new WDBCAction());
		load.add(new WPBCAction());
		// -----------------------------------
		JMenu dt = new JMenu("Decision Tree");
		dt.add(new DecisionTreeAction());
		// -----------------------------------
		metaData = new JMenu("Meta Data");
		// -----------------------------------
		JMenu db = new JMenu("Database");
		db.add(am.get(Actions.META_DATA));
		db.add(new AllTablesAction());
		db.add(new TypesAction());
		db.add(metaData);
		// -----------------------------------
		this.add(load);
		this.add(dt);
		this.add(db);
	}

	public void setConnected( boolean b)
	{
		if( b )
		{
			Action[] as = DBMDUtils.getResultSets( DTree.getApplication().getConnection() );
			for( Action a : as )
				metaData.add( a );
		}
		else
		{
			metaData.removeAll();
		}
	}
}
